package itheima.com.Day13.Test5;

public class Ticket implements Runnable {
  private  int tickets=100;
    private final Object lock = new Object();
    @Override
    public void run() {
        while (true){
            synchronized(lock){
                if(tickets<=0){
                    break;
                }else{
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickets--;
                    System.out.println(Thread.currentThread().getName()+"还剩"+tickets+"张票在出售");
                }
            }
        }
    }
}
